﻿using Microsoft.Extensions.DependencyInjection;
using MQTTnet.Client.Publishing;
using Newtonsoft.Json;
using PmSoft;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Modules.MQTT
{
    /// <summary>
    /// Mqtt设备通讯相关服务
    /// </summary>
    [UseDI(ServiceLifetime.Scoped)]
    public class MqttService
    {
        private readonly MqttRepository mqttRepository;

        public MqttService(MqttRepository mqttRepository)
        {
            this.mqttRepository = mqttRepository;
        }

        /// <summary>
        /// 发布消息
        /// </summary>
        /// <param name="topic">发布消息的主题</param>
        /// <param name="message">要发布的消息内容</param>
        /// <returns></returns>
        public async Task PublishAsync(string topic, string message)
        {
           
            await mqttRepository.PublishAsync(topic, message);
        }
    }
}
